<template>
	<view class="diy_details diy_div_adoption_information">
		<view v-if="Object.keys(obj).length!==0" class="warp">
			<view class="container">
				<view class="row">
					<view v-if="$check_field('get','pet_name')" class="col-12 col-md-6">
						<view class="diy_title">
							<span>宠物名称:</span>
						</view>
						<view class="diy_field diy_text">
							<text>
								{{obj["pet_name"]}}
							</text>
						</view>
					</view>
					<view v-if="$check_field('get','pet_species')" class="col-12 col-md-6">
						<view class="diy_title">
							<span>宠物种类:</span>
						</view>
						<view class="diy_field diy_text">
							<text>
								{{obj["pet_species"]}}
							</text>
						</view>
					</view>
					<view v-if="$check_field('get','user')" class="col-12 col-md-6">
						<view class="diy_title">
							<span>用户:</span>
						</view>
						<view class="diy_field diy_uid">
							<text>
								{{ get_user_user(obj['user']) }}
							</text>
						</view>
					</view>
					<view v-if="$check_field('get','full_name')" class="col-12 col-md-6">
						<view class="diy_title">
							<span>姓名:</span>
						</view>
						<view class="diy_field diy_text">
							<text>
								{{obj["full_name"]}}
							</text>
						</view>
					</view>
					<view v-if="$check_field('get','age')" class="col-12 col-md-6">
						<view class="diy_title">
							<span>年龄:</span>
						</view>
						<view class="diy_field diy_text">
							<text>
								{{obj["age"]}}
							</text>
						</view>
					</view>
					<view v-if="$check_field('get','contact_number')" class="col-12 col-md-6">
						<view class="diy_title">
							<span>联系电话:</span>
						</view>
						<view class="diy_field diy_text">
							<text>
								{{obj["contact_number"]}}
							</text>
						</view>
					</view>
					<view v-if="$check_field('get','adoption_address')" class="col-12 col-md-6">
						<view class="diy_title">
							<span>领养地址:</span>
						</view>
						<view class="diy_field diy_text">
							<text>
								{{obj["adoption_address"]}}
							</text>
						</view>
					</view>
					<view v-if="$check_field('get','audit_status')" class="col-12 col-md-6">
						<view class="diy_title">
							<span>审核状态:</span>
						</view>
						<view class="diy_field diy_text">
							<text>
								{{obj["audit_status"]}}
							</text>
						</view>
					</view>
					<view v-if="$check_field('get','review_reply')" class="col-12 col-md-6">
						<view class="diy_title">
							<span>审核回复:</span>
						</view>
						<view class="diy_field diy_desc">
							<text>
								{{ obj["review_reply"] }}
							</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import mixin from "@/mixins/component.js";
	export default {
		mixins: [mixin],
		props: {
			obj_goods: {
				type: Object,
				default(){
					return {}
				}
			},
			query:{
				type: Object,
				default(){
					return {adoption_information_id: 0
					}
				}
			}
		},
		data() {
			return {
				obj_goods_type: {},
				obj: {},
				// 用户列表
				list_user_user: [],
			}
		},
		methods: {
			async get_obj_goods_type() {
				var res = await this.$get("~/api/goods_type/get_obj", {
					name: this.obj_goods.type
				})

				if (res.result.obj) {
					this.obj_goods_type = res.result.obj
				} else {
					console.log("没有请求到商品分类");
				}
			},
			async get_obj_by_goods() {
				var {
					source_table,
					source_field
				} = this.obj_goods_type
				var {
					source_id
				} = this.obj_goods
				var query = {}
				query[source_field] = source_id
				this.$get("~/api/" + source_table + "/get_obj", {}, (res) => {
					if (res.result.obj) {
						this.obj = res.result.obj
					} else {
						console.log("没有请求到商品分类");
					}
				})
			},
			async get_obj_by_id(){
				var res = await this.$get("~/api/adoption_information/get_obj", {adoption_information_id:this.query.adoption_information_id
				})

				if (res.result && res.result.obj) {
					this.obj = res.result.obj
				} else {
					console.log("没有请求到商品分类");
				}
			},
			/**
			 * 获取普通用户用户列表
			 */
			async get_list_user_user() {
				var json = await this.$get("~/api/user/get_list?user_group=普通用户");
				if(json.result && json.result.list){
					this.list_user_user = json.result.list;
				}
				else if(json.error){
					console.error(json.error);
				}
			},
			get_user_user(id){
				var obj = this.list_user_user.getObj({"user_id":id});
				var ret = "";
				if(obj){
					ret = obj.nickname+"-"+obj.username;
					// if(obj.nickname){
					// 	ret = obj.nickname;
					// }
					// else{
					// 	ret = obj.username;
					// }
				}
				return ret;
			},
		},
		created() {
			this.get_list_user_user();
		},
		async onLoad(){
			if (Object.keys(this.obj_goods).length !== 0) {
				await this.get_obj_goods_type();
				await this.get_obj_by_goods();
			} else if (this.query["adoption_information_id"] !==0) {
				await this.get_obj_by_id();
			}
		}
	}
</script>

<style scoped>
	.div_adoption_information_details {}

	.details {
		background-color: #fff;
		margin-bottom: 0.5rem;
		padding: 1rem;
		font-size: 10px;
	}

	.item {
		display: flex;
		padding: 0.2rem 0;
		border-bottom: 1px solid #eee;
	}

	.left_text {
		flex: 0 0 25%;
	}

	.right_text {
		flex: 0 0 75%;
	}
	.edit_nav{
		text-align: center;
		background-color: #fff;
		padding: 0.3rem;
		margin: 0.1rem 1rem;
		border: 1px solid #eee;
		border-radius: 0.5rem;
	}
</style>
